package enumeration;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

/**
 * 我们定义「顺次数」为：每一位上的数字都比前一位上的数字大 1 的整数。
 * 请你返回由 [low, high] 范围内所有顺次数组成的 有序 列表（从小到大排序）。
 * <p>
 * 示例 1：
 * 输出：low = 100, high = 300
 * 输出：[123,234]
 * <p>
 * 示例 2：
 * 输出：low = 1000, high = 13000
 * 输出：[1234,2345,3456,4567,5678,6789,12345]
 *
 * @author Jisheng Huang
 * @version 20250421
 */
public class SequentialDigits_1291 {
    /**
     * Out loop from digit 1 to 9 and inner loop from out + 1 to 9. If the number is greater than low and less than
     * high, add to the res list
     *
     * @param low  the lower bound
     * @param high the upper bound
     * @return the list of number that satisfies the given condition
     */
    public static List<Integer> sequentialDigits(int low, int high) {
        List<Integer> res = new LinkedList<>();

        for (int i = 1; i <= 9; ++i) {
            int num = i;

            for (int j = i + 1; j <= 9; ++j) {
                num = num * 10 + j;

                if (num >= low && num <= high) {
                    res.add(num);
                }
            }
        }

        Collections.sort(res);

        return res;
    }

    public static void main(String[] args) {
        int low = 100;
        int high = 300;

        System.out.println(sequentialDigits(low, high));

        low = 1000;
        high = 13000;

        System.out.println(sequentialDigits(low, high));
    }
}
